layui.use(['form','jquery','jquery_cookie'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);


    /**
     * 表单的submit监听
     *      form.on('submit(按钮元素的lay-filter属性值)', function (data) {

            });
     */
    form.on('submit(saveBtn)', function (data) {
        // 所有表单元素的值
        console.log(data.field);

        // 发送ajax请求
        $.ajax({
            type:"post",
            url:ctx + "/user/updateInformation",
            data:{
                userName:data.field.userName,
                email:data.field.email,
                phone:data.field.phone
            },
            success:function (result) {
                // 判断是否修改成功
                if (result.code == 200) {

                    // 修改密码成功后，清空cookie数据，跳转到登录页面
                    layer.msg("用户信息修改成功", function () {

                        // 将用户信息设置到cookie中
                        $.cookie("userIdStr",result.result.userIdStr,{domain:"localhost",path:"/crm"});
                        $.cookie("userName",result.result.userName,{domain:"localhost",path:"/crm"});
                        $.cookie("trueName",result.result.trueName,{domain:"localhost",path:"/crm"});
                        // 跳转到登录页面(父窗口跳转)
                        window.parent.location.href = ctx + "/main";
                    });

                } else {
                    layer.msg(result.msg, {icon:5});
                }
            }

        });
    });


});